<table id="card_lost_info" data-options="fit:true"></table>
<div id="lost_toolbar" style="padding:0 10px;">
	<input class="icon-add" type="button" value="添加挂失记录" onclick="javascript:openLockWin()"
		style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<input class="icon-edit" type="button" value="修改" onclick="javascript:updateLoseStatus()"
	style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<input class="icon-reload" type="button" value="刷新" onclick="javascript:flushLost()"
		style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<div style="float:right;margin-right:20px;">
		查询条件：
		<select id="myselect_lost" style="text-align:center;">
			<option value="null">-- 请选择 --</option>
			<option value="学号">学号</option>
			<option value="是否领取">是否领取</option>
		</select>
		<input style="text-align:center;" type="text" id="input_text_lost">
		<input type="button" value="查询" onclick="javascript:findLock()"/>
	</div>
</div>
<script>
$(function(){
	$('#card_lost_info').datagrid({
		url:'../cardInfoServlet?t='+new Date(),
		queryParams:{op:"getAllLoseInfo"},
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'studentId',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'lids',title:'',width:100,align:'center',checkbox:true},
			{field:'lid',title:'编号',width:100,align:'center',sortable:true},
			{field:'studentId',title:'学号',width:100,align:'center'}, 
			{field:'ltime',title:'挂失时间',width:150,align:'center'}, 
			{field:'etime',title:'领取时间',width:150,align:'center'}, 
			{field:'lget',title:'是否领取',width:100,align:'center',formatter:function(value,rowData,rowIndex){
				if(value == 1) {
					return "未领取";
				} else {
					return "已领取";
				}
			}}
		]],
		toolbar:"#lost_toolbar"
	});
});

function flushLost(){
	$('#card_lost_info').datagrid("reload");
}

//添加丢失信息
function addLostInfo(){
	var studentId = $.trim($("#studentId_lost").val());
	var ltime=getDate(0);
	var etime=getDate(3);
	
	//为空判断
	if(sname!="" && sclass!="" && sdepartment!="") {
		$.post("../cardInfoServlet?t="+new Date(),
			{op:"addLostInfo",studentId:studentId,ltime:ltime,etime:etime},
			function(data){
			data = parseInt($.trim(data));
			if(data > 0) {
				$.messager.show({
					title:'成功提示',
					msg:'挂失信息添加成功!',
					timeout:3000,
					showType:'slide'
				});
				$("#studentId_lost").val("");
				$("#sname").val("");
				$("#sclass").val("");
				$("#sdepartment").val("");
				
				$("#add_lost_card_data").dialog("close");
				$('#card_lost_info').datagrid("reload");
			} else {
				$.messager.alert('错误提示','挂失信息添加失败!','error');
			}
		});
	} else {
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交!',
			timeout:3000,
			showType:'slide'
		});
	}
}

//打开添加丢失信息窗口
function openLockWin() {
	$("#add_lost_card_data").dialog("open");
	$("#studentId_lost").blur(function(){
		var studentId = $.trim($("#studentId_lost").val());
		if(studentId!="") {
			$.post("../cardInfoServlet?"+new Date(),{op:"getStuInfo",studentId:studentId},function(data){
				if(parseInt($.trim(data)) == 0) {
					$.messager.alert('错误提示','没有该信息!','error');
				} else {
					$("#lose_sname").val(data.stuInfo1[0].sname);
					$("#lose_sclass").val(data.stuInfo1[0].sclass);
					$("#lose_sdepartment").val(data.stuInfo1[0].sdepartment);
				}
			},"json");
		} else {
			$.messager.show({
				title:'温馨提示',
				msg:'您输入的信息不完整，请确认后再提交!',
				timeout:3000,
				showType:'slide'
			});
		}
	});
}

//查询方法
function findLock() {
	var myselect = $.trim($("#myselect_lost").val());
	var info = $.trim($("#input_text_lost").val());
	if (myselect != "null" && info != "") {
		$.post("../cardInfoServlet?t="+new Date(),{op:"selectLostInfo",myselect:myselect,info:info},
			function(data){
			if(parseInt($.trim(data))==0){
				$.messager.alert('错误提示','没有该信息!','error');
			}else {
				$('#card_manage_data').datagrid("loadData",data.rows);
			}
		},"json");
	}else{
		$.messager.show({
			title : '温馨提示',
			msg : '您输入的信息不完整，请确认后再提交!',
			timeout : 3000,
			showType : 'slide'
		});
	}
}

//获取时间的方法
function getDate(val){
	var date = new Date();
	
	date.setDate(date.getDate()+val);
	
	var year = date.getFullYear().toString();
	var month = (date.getMonth()+1).toString();
	var ri = date.getDate();
	
	var d=year+"-"+month+"-"+ri;
	return d;
}

//领取操作
function updateLoseStatus(){
	var lids=$('#card_lost_info').datagrid('getSelections');
	if(lids.length>0){
		var temp="";
		for(var i=0;i<lids.length;i++){
			if(lids[i].lget==1){
				temp+=lids[i].studentId+",";
			}
		}
		if(temp!=""){
			temp=temp.substring(0,temp.lastIndexOf(","));
			$.post("../cardInfoServlet?t="+new Date(),{op:"updateLoseInfo",temp:temp},function(data){
				console.info(data);
				if(parseInt($.trim(data))>0){
					$.messager.show({
						title : '温馨提示',
						msg : '挂失信息修改成功!',
						timeout : 3000,
						showType : 'slide'
					});
					$('#card_lost_info').datagrid("reload");
				}else{
					$.messager.alert('错误提示','挂失信息修改失败,请稍后重试!','error');
				}
			});
		}else{
			$.messager.alert('错误提示','已经全部领取!','error');
		}
	}else{
		$.messager.alert('错误提示','请选择需要修改的信息!','error');
	}
}

</script>
<div id="add_lost_card_data" class="easyui-dialog" title="挂失" style="width:400px;height:280px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="studentId_lost">学号：</label><input type="text" id="studentId_lost">
		<br /> <br /> 
		<label for="sname">姓名：</label><input type="text" id="lose_sname" disabled="disabled">
		<br /> <br />
		<label for="sclass">班级：</label><input type="text" id="lose_sclass" disabled="disabled">
		<br /> <br />
		<label for="sdepartment">学院：</label><input type="text" id="lose_sdepartment" disabled="disabled">
		<br /> <br />
		<input style="padding:5px 25px;" type="button" onclick="addLostInfo()" value="挂失此卡">
	</p>
</div>
